package bbsimon.first.model.shopcart;

import bbsimon.first.model.shopcart.BookModel;
import java.util.ArrayList;
import java.util.List;

public class CartModel {
	private List<BookModel> _books;

	public CartModel() {
		_books = new ArrayList<BookModel>();
	}

	public boolean add(BookModel bm) {
		return _books.add(bm);	
	}

	public boolean remove(BookModel bm) {
		return _books.remove(bm);
	}

	public List<BookModel> getBooks() {
		return _books;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();
		for(BookModel bm : _books) {
			sb.append(bm.toString() + "\n");
		}
		return sb.toString();
	}

	public boolean removeAll() {
		boolean b = false;
		for(BookModel bm : _books) {
			b = _books.remove(bm);	
			if(!b)
				return false;	
		}
		return true;
	}

	public BookModel find(String BookName) {
		for(BookModel bm : _books) {
			if(bm.getBookName().equals(BookName)) {
				return bm;
			}
		}
	}
}
